/* -----------------------------------------------------------------------
 * Demonstration of how to write unit tests for dominion-base
 * Include the following lines in your makefile:
 *
 * unittest2: unittest2.c dominion.o rngs.o
 *      gcc -o unittest2 -g  unittest2.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int p, r, handCount, result;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int clear[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        clear[i] = curse;
    }
	
	/* there are 27 cards, 0-26 */
	
    printf ("\nStarting tests fullDeckCount(). # players: %d Seed: %d\n", numPlayer, seed);
	//set card #'s
	//run fullDeckCount
	//if our assert passes we know it worked.
	//questions: do I need to initialize the game? yes
	//just look at state->supplyCount[]
	
	//MAX_PLAYERS is always < MAX_HAND
	//so will be hand amount
    for (p = 0; p < numPlayer; p++)
    {
		//cardCount is always < MAX_DECK
		//so will be discard
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
		
#if (NOISY_TEST == 1)
            printf("The full deck count for player%d\n", p);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			memcpy(G.deck[p], clear, sizeof(int) * MAX_HAND);//clear everything to curse
			memcpy(G.hand[p], clear, sizeof(int) * MAX_HAND);//clear everything to curse
			memcpy(G.discard[p], clear, sizeof(int) * MAX_HAND);//clear everything to curse
			
            G.deckCount[p] = handCount;               // set the number of cards on hand
            memcpy(G.deck[p], coppers, sizeof(int) * handCount); // set all the cards to copper
            result = fullDeckCount(p, copper, &G);
#if (NOISY_TEST == 1)
            printf("full deck count = %d, expected = %d\n", result, handCount);
#endif
            assert(result == handCount); // check if the number of coins is correct
            
			G.handCount[p] = handCount;               // set the number of cards on hand
            memcpy(G.hand[p], coppers, sizeof(int) * handCount); // set all the cards to copper
            result = fullDeckCount(p, copper, &G);
#if (NOISY_TEST == 1)
            printf("full deck count = %d, expected = %d\n", result, handCount * 2);
#endif
            assert(result == handCount * 2); // check if the number of coins is correct
				
			G.discardCount[p] = handCount;
            memcpy(G.discard[p], coppers, sizeof(int) * handCount); // set all the cards to gold
			result = fullDeckCount(p, copper, &G);
#if (NOISY_TEST == 1)
            printf("full deck count = %d, expected = %d\n", result, handCount * 3);
#endif
			assert(result == (handCount * 3)); // check if the number of coins is correct
         
        }
    }

    printf("\tAll fullDeckCount() tests completed successfully...\n");

    return 0;
}
